<?php
namespace Common\Model;

use Think\Model;

class PositionContentModel extends Model
{
    private $_db;
    public function __construct() {
        $this->_db = M('position_content');
    }

    /**
     * 推荐位查询
     * @param array $data
     * @param int $limit
     * @return mixed
     */
    public function select($data = [] , $limit=0) {
        if ($data['title']){
            $data['title'] = ['like' , '%' . $data['title'] . '%'];
        }
        $this->_db->where($data)->order('listorder desc , position_id desc');
        if ($limit){
            $this->_db->limit($limit);
        }
        $res = $this->_db->select();
        return $res;
    }
    /**
     * 文章内容插入
     * @param $data
     * @return int
     */
    public function insert($data)
    {
        if (!$data || !is_array($data)){
            return 0;
        }
        $data['create_time'] = time();
        /*编辑器内的字符转义 */
        if ($data['content'] && isset($data['content'])){
            $data['content'] = htmlspecialchars($data['content']);
        }
        return $this->_db->add($data);
    }
}